package com.example.foods.service.impl;

import com.example.foods.common.Utils;
import com.example.foods.data.AdminMapper;
import com.example.foods.domain.AdminInfo;
import com.example.foods.domain.UpdateAdminInfo;
import com.example.foods.entity.Admin;
import com.example.foods.service.AdminService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AdminServiceImpl implements AdminService {

    @Resource
    private AdminMapper adminMapper;

    @Override
    public AdminInfo findByAdminAccount(String adminAccount) {
        Admin admin=this.adminMapper.findByAdminAccount(adminAccount);
        AdminInfo adminInfo=null;
        if(admin!=null){
            adminInfo=new AdminInfo();
            BeanUtils.copyProperties(admin,adminInfo);
        }
        return adminInfo;
    }

    @Override
    public void updatePwd(UpdateAdminInfo updateAdminInfo) {
        Admin admin = new Admin();
        admin.setAdminPwd(Utils.encodePassword(updateAdminInfo.getPwd()));
        admin.setAdminAccount(updateAdminInfo.getUserId());
        adminMapper.updatePwd(admin);
    }

    @Override
    public void updateMobile(UpdateAdminInfo updateAdminInfo) {
        Admin admin = new Admin();
        admin.setMobile(updateAdminInfo.getMobile());
        admin.setAdminAccount(updateAdminInfo.getUserId());
        adminMapper.updateMobile(admin);

    }

    @Override
    public void updateRealName(UpdateAdminInfo updateAdminInfo) {
        Admin admin = new Admin();
        admin.setRealName(updateAdminInfo.getRealName());
        admin.setAdminAccount(updateAdminInfo.getUserId());
        adminMapper.updateRealName(admin);
    }
}
